package org.ahuanlien.crm.web.controller;

import org.ahuanlien.crm.domain.BillRecord;
import org.ahuanlien.crm.query.BillRecordQueryObject;
import org.ahuanlien.crm.service.IBillRecordService;
import org.ahuanlien.crm.util.JSONResult;
import org.ahuanlien.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("billRecord")
public class BillRecordController {

	@Autowired
	private IBillRecordService billRecordService;


	//打开页面和数据获取分开
	@RequestMapping("view")
	public String view() {

		return "billRecord/view";
	}

	@RequestMapping("query")
	@ResponseBody
	public PageResult query(BillRecordQueryObject qo) {
		PageResult result = billRecordService.query(qo);
		return result;
	}
	@RequestMapping("saveOrUpdate")
	@ResponseBody
	public JSONResult saveOrUpdate(BillRecord billRecord){
		try {
			if(billRecord.getId()!= null){
				billRecordService.updateByPrimaryKey(billRecord);
			}else{
				billRecordService.insert(billRecord);
			}
			return new JSONResult();
		} catch (Exception e) {
			e.printStackTrace();
			return new JSONResult().mark("保存失败");
		}
	}

	@RequestMapping("update")
	@ResponseBody
	public JSONResult update(BillRecord billRecord,Long id){
		try {
            billRecord.setId(id);
				billRecordService.update(billRecord);
			return new JSONResult();
		} catch (Exception e) {
			e.printStackTrace();
			return new JSONResult().mark("保存失败");
		}
	}



	@RequestMapping("delete")
	@ResponseBody
	public JSONResult delete(Long id) {
		try {
			billRecordService.deleteByPrimaryKey(id);
		} catch (Exception e) {
			e.printStackTrace();
			return JSONResult.mark("操作失败");
		}
		return JSONResult.success("操作成功");
	}

	/*@RequestMapping("pay")
	@ResponseBody
	public JSONResult pay(Long id){
		if(id != null){
			billRecordService.pay(id);
			return new JSONResult();
		}else {
			return new JSONResult().mark("缴费失败！");
		}
	}*/
}
